package wu.mapper;

import org.apache.ibatis.annotations.*;
import wu.pojo.NiuStudent;
import wu.pojo.Student;

import java.util.List;
@Mapper
public interface StudentMapper2 {
//只声明方法，方法名要和 XML 映射文件中的 <insert> 标签的 id 属性值对应
    @Select("SELECT niu_id FROM students2")
    List<Integer> getNiuIds();

    Student getStudentWithUserNiuById2(int niu_id);

    NiuStudent getStudentByIdAndTableName2(@Param("tableName") String tableName, @Param("niu_id") int niu_id);


    @Select("SELECT class, name, niu_Contestants, niu_id FROM students2")
    @Results({
            @Result(property = "classInfo", column = "class"),
            @Result(property = "name", column = "name"),
            @Result(property = "niu_Contestants", column = "niu_Contestants"),
            @Result(property = "niu_id", column = "niu_id")
    })
    List<Student> getstudents2();

    @Select("SELECT class, name, niu_Contestants, niu_id FROM students2 WHERE niu_id = #{niuId}")
    @Results({
            @Result(property = "classInfo", column = "class"),
            @Result(property = "name", column = "name"),
            @Result(property = "niu_Contestants", column = "niu_Contestants"),
            @Result(property = "niu_id", column = "niu_id")
    })
    Student getStudentById(int niuId);

    @Insert("INSERT INTO students2 (class, name, niu_Contestants,niu_id) VALUES (#{classInfo}, #{name}, #{niu_Contestants},#{niu_id})")
    void insertStudent(Student student);

    @Update("UPDATE students2 SET class = #{classInfo}, name = #{name}, niu_Contestants = #{niu_Contestants} WHERE niu_id = #{niu_id}")
    int updateStudent(Student student);

    @Delete("DELETE FROM students2 WHERE niu_id = #{niu_id}")
    void deleteStudent(int niuId);

}
